package core

import jsoniter "github.com/json-iterator/go"

const COMMAND_SHOW_DBS = "show_dbs"
const COMMAND_SHOW_COLS = "show_cols"
const COMMAND_AGGREGATE = "aggregate"
const COMMAND_COUNT = "count"
const COMMAND_INSERT = "insert"
const COMMAND_UPDATE = "update"
const COMMAND_DELETE = "delete"
const COMMAND_REPLACE = "replace"
const COMMAND_DROP_DB = "drop_db"

//var COMMAND_MAP = []map[string]string{
//	"REPLACE": 	"REPLACE",
//}

type Command struct {
	DB         string      `json:"db"`
	Collection string      `json:"collection"`
	Command    int         `json:"command"`
	Data       interface{} `json:"data"`
}

func getArgs(msg string) (command *Command, err error) {
	var data map[string]interface{}
	err = jsoniter.Unmarshal([]byte(msg), &data)
	if err != nil {
		return
	}
	command = &Command{}
	command.DB = data["db"].(string)
	command.Collection = data["collection"].(string)
	command.Data = data["data"]
	command.Command = data["command"].(int)
	return
}
